package com.javaspeak.concurrency.lock.custom.reentrant;

import java.util.Comparator;

/**
 * This Comparator is used for sorting the CounterValues in a list by their
 * counter values.
 * <p>
 * The reason we are doing the sort is that we will then compare the timestamps
 * in the ReEntrantLockTest and make sure that the timestamps are in increasing
 * order.
 *
 * @author John Dickerson
 */
public class CounterValueComparator implements Comparator<CounterValue> {

    @Override
    public int compare(
            CounterValue counterValue, CounterValue otherCounterValue ) {

        Integer value =  new Integer( counterValue.getValue() );
        Integer otherValue = new Integer( otherCounterValue.getValue() );

        return value.compareTo( otherValue );
    }
}
